<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{
            width: 500px;
            height: 300px;
            border: 1px solid #ccc;
            overflow-y: auto;
        }
        #div2{
            width: 500px;
            height: 100px;
            border: 1px solid #ccc;
            margin: 50px 0 10px;
        }
        #div3 {
            width: 500px;
           display: flex;
           justify-content: space-between;
        }
        #div3 span:nth-child(1){
            color: red;
        }
        textarea{
            width: 100%;
            height: 100%;
        }
        .em1{
            float: left;
        }
        .em2{
            float: right;
        }
    </style>
</head>
<body>
    <div id="div1"></div>
    <div id="div2">
        <textarea name="" id="t" maxlength="20"></textarea>
    </div>
   
    <div id="div3">
        <button id="btn">提交</button>
        <div>
            <span id="span1">0</span><span>/</span><span>20</span>
        </div>

</div>

<script src="utils.js"></script>
    <script>
        // 定义字数变量
        var num=0
        btn.onclick=function(){
            var date= new Date()
            // 输入内容和日期
            div1.innerHTML+="<em class='em1'>"+t.value+"</em>"+"<em class='em2'>"+dates(date)+"</em>"+"<br>"
            span1.innerHTML=0
            num=0
            t.value=""
        }
        t.onkeydown=function(e){
           
            if(e.keyCode==8){
                num--
            }else{
                num++
            }
            if(num>=20){
                num=20
            }else if(num<=0){
                num=0
            }
            span1.innerHTML=num
            if(e.ctrlKey&&e.keyCode==13){
                var date= new Date()
                div1.innerHTML+="<em class='em1'>"+t.value+"</em>"+"<em class='em2'>"+dates(date)+"</em>"+"<br>"
                t.value=""
                span1.innerHTML=0
                num=0
            }
        }
      

    </script>
</body>

</html>